var oss = require('ali-oss');
var M=require('ming_node')
var fs = require("fs")
var path = require("path")

M.log_display_time=false

// config={
//   accessKeyId: 'LTAIMre888eRk2Kk',
//   accessKeySecret: 'ExM0o0OBy2UTfMXso6ArrWiAOyhKMN',
//   bucket: 'ming-bucket-01',
//   region: 'oss-cn-beijing',
//   ossPath:'datasheet/math/',
//   filePath:'D:\\workspace\\gitee\\ming_api_mock_plugins\\data\\'
// }


config={
  accessKeyId: 'LTAI2KwBDCCOCmgc',
  accessKeySecret: 't8R9LyB6GOdKF04u0VqmhXFYtkxIqA',
  bucket: 'langjie',
  region: 'oss-cn-hangzhou',
  ossPath:'public/img/gallery/',
  filePath:'D:\\workspace\\gitee\\ming_api_mock_plugins\\data\\',
  filePath1:'D:\\xampp\\htdocs\\nodejs\\admin\\public\\img\\gallery\\'
}


var client  = oss(config);

async function listOss() {
  client.useBucket(config.bucket);  
    var result =await  client.list({ "prefix":config.ossPath});
    return result.objects.map(u=>u.name.substring(u.name.lastIndexOf('/')+1))


}
  


function listFile(){
  let rList=[]
  path=config.filePath;
	var pa = fs.readdirSync(path);
	pa.forEach(function(ele,index){
		var info = fs.statSync(path+"/"+ele)	
		if(info.isDirectory()){
			//console.log("dir: "+ele)
		//	readDirSync(path+"/"+ele);
		}else{
		//	console.log("file: "+ele)
      rList.push(ele)
		}	
	})
  return rList;
}

if(1)
+async function(){  
  ossList=await listOss();

    console.log(ossList.length,ossList)

}();



if(0)
+async function(){  
    ossList=await listOss()
    fileList=await listFile()

    console.log("==============ossList===================")
    console.log(ossList.length,ossList)
    console.log("==============fileList===================")
    console.log(fileList.length,ossList)


    oldList=fileList;
    newList=ossList;

    oy_nn_list=[];
    on_ny_list=[]

    for(let i=0;i<oldList.length;i++){
        if(newList.indexOf(oldList[i])===-1){
            oy_nn_list.push(oldList[i])
            M.log(`#oss缺少 ${oldList[i]}`)
        }
    }

    for(let i=0;i<newList.length;i++){
        if(oldList.indexOf(newList[i])===-1){
            on_ny_list.push(newList[i])
            M.log(`#oss多了  ${newList[i]}`)
        }
    }
}();


